const fs = require('fs');
const fpath = require('path');
const { formaData } = require('../utils/date_time');
const { exist } = require('../request/local');
const path = require('path');
const filePath = fpath.join(__dirname, 'index.txt');
console.log(filePath.toString());
const content = fs.readFileSync(filePath, 'utf8');
const array = content.split('\n');
if (array.length < 3) {
    throw Error('配置错误');
}
const host = array[0].trim();
const tag = array[1].trim();
const explain = array[2].trim();
const jsonBean = { host, explain, tag }
const newPath = fpath.join(__dirname, '../config', tag + '.json');
const ctime = formaData(new Date());
jsonBean.ctime = ctime;
if (!exist(newPath)) {
    fs.writeFileSync(newPath, JSON.stringify(jsonBean, null, '\t'));
}
const parsePath = fpath.join(__dirname, '../parse', tag + '.js');
if (!exist(parsePath)) {
    fs.writeFileSync(parsePath,
        `const cheerio = require('cheerio');

function videoList(content) {
    const $ = cheerio.load(content);
    return {};
}

function videoPlayPath(content) {
    const $ = cheerio.load(content);
    return {};
}

function videoInfo(content) {
    const $ = cheerio.load(content);
    return {};
}

function searchVideo(content) {
    const $ = cheerio.load(content);
    const list = [];
    if (list.length == 0) throw Error('未搜到相关数据');
    return {};
}

function parsePage($){
    $('')
}

module.exports = { videoList, videoInfo, videoPlayPath, searchVideo }
`);
}
const searchPath = fpath.join(__dirname, '../search', tag + '.js');
if (!exist(searchPath)) {
    fs.writeFileSync(searchPath,
        `function searchHref(filter) {
    return undefined;
}

function searchPage(filter, page) {
    return undefined;
}

module.exports = { searchHref, searchPage }`);
}
console.log('--------------------------------------------');
console.log(parsePath);
console.log(searchPath);
console.log('结束：' + newPath.toString());